package com.example.spring.thread.create;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author: orange
 * @create: 2023-08-04 21:43
 * @description:
 */
public class CallableExampleMain {
    public static void main(String[] args) {
        try {
            FutureTask<String> futureTask = new FutureTask<>(new Callable<String>() {
                @Override
                public String call() throws Exception {
                    try {
                        Thread.sleep(1000);
                        System.out.println("Thread.currentThread().getName() = " + Thread.currentThread().getName());;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return "返回一个值";
                }
            });

            Thread thread = new Thread(futureTask, "futureTask");
            thread.start();
            System.out.println("futureTask = " + futureTask.get());

            System.out.println(Thread.currentThread().getName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
